<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Manageadmins.php 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitepage_Model_DbTable_Manageadmins extends Engine_Db_Table {
	
	protected $_rowClass = "Sitepage_Model_Manageadmin";
	
	/**
	 * Return manage admins
	 *
	 * @param int $page_id
	 */
	public function getManageAdminUser($page_id) {
		
		$usertable = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
		$userName = $usertable->info ( 'name' );
		$manageName = $this->info ( 'name' );
		$manageHistoriesQuery = $this->select ()->setIntegrityCheck ( false )->from ( $manageName )->joinleft ( $userName, $manageName . '.page_id = ' . $userName . '.user_id', array ('displayname', 'photo_id' ) )->where ( 'page_id = ?', $page_id );
		return Zend_Paginator::factory ( $manageHistoriesQuery );
	}
	
	/**
	 * Return manage admin ids
	 *
	 * @param int $page_id
	 */
	public function getManageAdmin($page_id) {
		
		$select = $this->select ()->from ( $this->info ( 'name' ) )->where ( 'page_id = ?', $page_id );
		return $this->fetchAll ( $select );
	}
	
	/**
	 * Return manage admin pages_id
	 *
	 * @param int $viewer_id
	 */
	public function getManageAdminPages($viewer_id) {
		
		$select = $this->select ()->from ( $this->info ( 'name' ), 'page_id' )->where ( 'user_id = ?', $viewer_id );
		return $this->fetchAll ( $select );
	}
	
	/**
	 * Return linked pages result
	 *
	 * @param int $page_id
	 */
	public function linkedPages($page_id) {
		
		$manageAdminName = $this->info ( 'name' );
		$select = $this->select ()->from ( $manageAdminName, 'user_id' )->where ( 'page_id = ?', $page_id );
		return $user_idarray = $this->fetchAll ( $select )->toArray ();
	}
	
	/**
	 * Return featured manage admins
	 *
	 * @param int $page_id
	 */
	public function featuredAdmins($page_id) {
		
		$select = $this->select ()->where ( 'featured = ?', 1 )->where ( 'page_id = ?', $page_id );
		return $this->fetchAll ( $select );
	}

}
?>